// Copyright  2011, 2012 Petr TALLA. [petr.talla@gmail.com]
// This file is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;  without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
// [http://www.gnu.org/copyleft/lesser.html]
//=============================================================================
#pragma once

#include "./TcCmd.h"
#include "./TcCmdProcess.h"
#include <map>
#include <list>

class TcCmdEngine;
class TcArgCol;
class TcCmdLog;
class TcCmdEngineMsgReceiver;

//=============================================================================
class TcCmdEngine {
//=============================================================================
public:
//<CONSTRUCTION>
    TcCmdEngine();
    static TcCmdEngine& engine();
//<NEIGHBOURS>
    void append(TcCmdProcess* process);
//<METHODS>
    TcCmd* registerCmd(const char* name, TcCmd::Cmd cmd);
    int  execute(TcArgCol* args, bool queued);
    TcCmd* find(TcArgCol& args);
    bool frontControllerActive(void) {return frontControllerActive_;};
    void executeQueue(void);
    void queuedSetOn() { queued_ = true; };
//=============================================================================
protected:
//<DATA>
    std::map<std::string, TcCmd*> items_;
    std::list<TcCmdProcess*>      processes_;
    std::list<TcArgCol*>          queue_;
    std::list<TcCmdEngineMsgReceiver*>  msgReceivers_;
    bool                          frontControllerActive_;
    bool                          queued_;
    int                           loop_;
    bool                          pendingExecution_;
//<FRIENDS>
    friend class TcCmdProcessExe;
    friend class TcCmdEngineMsgReceiver;
};

